<?php
namespace app\api\controller;
use app\common\BaseController;
use think\Db;
class Brokerage extends BaseController{
    public function __construct(){
        parent::__construct();
    }
    
    public function index(){  
        $params = $this->request->param();
        $where=[];
        if(isset($params['job_no'])){
            $where['job_no']=$params['job_no'];
        }      
        $where['begdate'] = [['>=',str_replace("-","",$params['start_date'])],['<=',str_replace("-","",$params['end_date'])]];
        $sub=Db::table('lt_policy')  
        ->field("*,count(*) as num,sum(premium) as total")
        ->where($where)       
        ->group('insure_code')        
        ->buildSql();
        $data=Db::table("{$sub} a")  
        ->field("a.*,b.*,total*(b.rate/100) as fee")      
        ->join("lt_insure b","a.insure_code=b.insure_code")
        ->select();
        return $data;
    }
}